import torch
from pyecharts import options as opts
from pyecharts.charts import Scatter

from algorithms.large.lmocso import LMOCSO
from indicators.igd import IGD
from problems.LSMOP.LSMOP_1 import LSMOP1
from utils.vectors import get_ref_vectors

if __name__ == '__main__':
    lmocso = LMOCSO(LSMOP1(200, 2), 100, 20_0000)
    lmocso.run()
    y = lmocso.population.get_attr('obj')
    print(IGD.value(y, get_ref_vectors(10000, 2)))
    scatter = Scatter()
    scatter.add_xaxis(xaxis_data=torch.flatten(lmocso.ref_vectors[:, 0]).cpu().detach().numpy())
    scatter.add_yaxis(series_name=lmocso.problem.name + '-PF',
                      y_axis=torch.flatten(lmocso.ref_vectors[:, 1]).cpu().detach().numpy(),
                      itemstyle_opts=opts.ItemStyleOpts(color="red"))
    scatter.add_xaxis(xaxis_data=torch.flatten(y[:, 0]).cpu().detach().numpy())
    scatter.add_yaxis(series_name=lmocso.problem.name + '-PF-get', y_axis=torch.flatten(y[:, 1]).cpu().detach().numpy(),
                      itemstyle_opts=opts.ItemStyleOpts(color="blue"))
    scatter.set_series_opts(label_opts=opts.LabelOpts(is_show=False))

    scatter.load_javascript()

    scatter.render('lmocos.html')
